package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CwParking;
import com.ruoyi.system.service.ICwParkingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车位费Controller
 * 
 * @author ruoyi
 * @date 2022-11-29
 */
@RestController
@RequestMapping("/system/parking")
public class CwParkingController extends BaseController
{
    @Autowired
    private ICwParkingService cwParkingService;

    /**
     * 查询车位费列表
     */
    @PreAuthorize("@ss.hasPermi('system:parking:list')")
    @GetMapping("/list")
    public TableDataInfo list(CwParking cwParking)
    {
        startPage();
        List<CwParking> list = cwParkingService.selectCwParkingList(cwParking);
        return getDataTable(list);
    }

    /**
     * 导出车位费列表
     */
    @PreAuthorize("@ss.hasPermi('system:parking:export')")
    @Log(title = "车位费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CwParking cwParking)
    {
        List<CwParking> list = cwParkingService.selectCwParkingList(cwParking);
        ExcelUtil<CwParking> util = new ExcelUtil<CwParking>(CwParking.class);
        util.exportExcel(response, list, "车位费数据");
    }

    /**
     * 获取车位费详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:parking:query')")
    @GetMapping(value = "/{pid}")
    public AjaxResult getInfo(@PathVariable("pid") Long pid)
    {
        return success(cwParkingService.selectCwParkingByPid(pid));
    }

    /**
     * 新增车位费
     */
    @PreAuthorize("@ss.hasPermi('system:parking:add')")
    @Log(title = "车位费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CwParking cwParking)

    {
        Long salestime = cwParking.setSalestime(cwParking.getSalestime() / 1000);
        Long Duetime = cwParking.setDuetime(cwParking.getDuetime() / 1000);

        return toAjax(cwParkingService.insertCwParking(cwParking));
    }

    /**
     * 修改车位费
     */
    @PreAuthorize("@ss.hasPermi('system:parking:edit')")
    @Log(title = "车位费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CwParking cwParking)
    {

        return toAjax(cwParkingService.updateCwParking(cwParking));
    }

    /**
     * 删除车位费
     */
    @PreAuthorize("@ss.hasPermi('system:parking:remove')")
    @Log(title = "车位费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pids}")
    public AjaxResult remove(@PathVariable Long[] pids)
    {
        return toAjax(cwParkingService.deleteCwParkingByPids(pids));
    }
}
